// pages/ngl/ngl.js  getStatusByPhone

import {  getStatusByPhone} from '../../api/tbPersonal'

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:0,


    selected: 0,
    color: "#A7A9B8",
    selectedColor: "#644C04",
    borderStyle: "white",
    list: [
      {
            pagePath: "/pages/main/main",
            iconPath: "../../icons/img/main/menu_icon-01.png",
            selectedIconPath: "../../icons/img/main/menu_icon-05.png",
            text: "首页"
        },
        {
            pagePath: "/pages/ngl/ngl",
            iconPath: "../../icons/img/main/menu_icon-02.png",
            selectedIconPath: "../../icons/img/main/menu_icon-06.png",
            text: "通行证"
        } 
    ]
  },
  switchTab(e) {
    const data = e.currentTarget.dataset
    const url = data.path
    wx.switchTab({ url });
    this.setData({
        selected: data.index
    })

    console.log(data);
},
  gotoMain () {
    console.log(this.data.type)
    if(this.data.type !== '1'){
      wx.switchTab({
        url: '../main/main',
      })
    }
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if(options.type){
      this.setData({ 
        type:options.type
       })
       wx.setStorageSync('roleType',options.type)
    }
    if(wx.getStorageSync('roleType')){
      this.setData({ 
         type:wx.getStorageSync('roleType')
      })
    }
    if(wx.getStorageSync('phone')){
      //未完成 调取接口获取 新的roletype类型
      if(wx.getStorageSync('roleType') =='4'){

      }else{
        this.getStatusByPhone()
      }
    }
    wx.getSetting({
      success: function (r) {
        console.info(r)
      }
    })

  },
  getStatusByPhone(){
    let params = {
      phone:wx.getStorageSync('phone')
    }
    getStatusByPhone(params).then(res => {
      console.log(res)
      if(res){
        this.setData({
          type:res
        })
      }
        // console.log(res)
      }).catch(_=>{
        console.log(_)
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})